import { Controller } from "../../mvc/core/Controller";
import { NewAreaRechargeIcon } from "../view/newAreaRecharg/NewAreaRechargeIcon";
import { INewAreaRechargePeopleModule } from "../../../modules/interfaces/INewAreaRechargePeopleModule";
import { NewAreaRechargePeopleModule } from "../../../modules/NewAreaRechargePeopleModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SRechargeNumTargetActiveProcessInfo } from "../../../Message/Game/SRechargeNumTargetActiveProcessInfo";
import { SRechargeNumTargetPlayerInfo } from "../../../Message/Game/SRechargeNumTargetPlayerInfo";
import { SRechargeNumTargetPlayerReward } from "../../../Message/Game/SRechargeNumTargetPlayerReward";
import { ClockManager } from "../manager/ClockManager";
type int = number;
//class NewAreaRechargePeopleController
    
    export  class NewAreaRechargePeopleController extends Controller
    {
       

        public get icon(): NewAreaRechargeIcon
        {
            if (!this._icon) 
            {
                this._icon = new NewAreaRechargeIcon();
                this._icon.updateIconInfo();
            }
            return this._icon;
        }

        public get module(): INewAreaRechargePeopleModule
        {
            if (!this._module) 
            {
                this._module = new NewAreaRechargePeopleModule();
            }
            return this._module;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.OnClickNewAreaRechargeIcon, this.onClickIcon);
            Dispatcher.addEventListener(EventName.GetNewAreaRechargeGift, this.onGetGiftBtnClick);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateRechargeNumTargetPlayerInfo, this.openView);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRechargeNumTargetProcessInfo, this.activeIsOpen);
            return;
        }

        /* internal  */onGetGiftBtnClick(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.active.getNewAreaRechargeGift(loc1);
            return;
        }

        /* internal  */activeIsOpen(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRechargeNumTargetActiveProcessInfo;
            if (loc1.isOpen) 
            {
                this.icon.show();
            }
            else 
            {
                this.icon.hide();
            }
            return;
        }

        /* internal  */openView(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRechargeNumTargetPlayerInfo;
            var loc2=(loc1.rewardState[(loc1.rewardState.length - 1)] as SRechargeNumTargetPlayerReward).node;
            var loc3=(loc1.endDate.time - ClockManager.instance.nowDate.time) / 1000;
            if (!this.module.isHide) 
            {
                this.module.updateItem(loc1.rewardState);
                this.module.setProcess(loc1.process, loc2);
                this.module.setActiveTime(loc3);
            }
            return;
        }

        /* internal  */onClickIcon(arg1: DataEvent): void
        {
            if (this.module.isHide) 
            {
                this.module.show();
                GameProxy.active.getNewAreaRechargeInfo();
            }
            else 
            {
                this.module.hide();
            }
            return;
        }

        private /* var */_icon: NewAreaRechargeIcon;

        private /* var */_module: INewAreaRechargePeopleModule;
    }
